package com.qd.pay.domain;

import com.fasterxml.jackson.databind.JsonNode;
import lombok.Data;
import lombok.experimental.Accessors;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.math.BigDecimal;
import java.time.LocalDateTime;


/**
 * @author sjk
 */
@Data
@Accessors(chain = true)
public class OrderDTO {

    private String orderId;

    private String outTradeNo;

    @NotBlank(message = "第三方订单ID不能为空")
    @Size(max = 50, message = "第三方订单ID长度不能超过{max}位")
    private String thirdPartyOrder;

    @NotBlank(message = "商品描述不能为空")
    @Size(max = 128, message = "商品描述长度不能超过{max}位")
    private String body;
    /**
     * 商品名称
     */
    @Size(max = 256, message = "商品名称长度不能超过{max}位")
    private String subject;

    @Size(max = 50, message = "付款人长度不能超过{max}位")
    private String personId;

    @NotNull(message = "订单金额不能为空")
    private BigDecimal payAmount;

    @Size(max = 20, message = "ipAddress长度不能超过{max}位")
    private String ipAddress;

    @Size(max = 256, message = "notifyUrl长度不能超过{max}位")
    private String notifyUrl;

    private LocalDateTime sendTime;

    private LocalDateTime updateTime;

    /**
     * 0微信1支付宝2天府银行(微信小程序)3天府银行(微信公众号)
     */
    @NotNull(message = "订单类型不能为空")
    private Integer type;

    private Integer state;

    private String appId;
    private String openid;
    /**
     * JSAPI--JSAPI支付（或小程序支付）、NATIVE--Native支付、APP--app支付，MWEB--H5支付
     */
    private String tradeType = "JSAPI";
    /**
     * 服务商号
     */
    @Size(max = 50, message = "服务商号长度不能超过{max}位")
    private String partner;
    /**
     * 特约商户号
     */
    @Size(max = 50, message = "特约商户号长度不能超过{max}位")
    private String subPartner;
    /**
     * 支付子产品参数（天府银行聚合支付）
     */
    private JsonNode channelDetails;
    /**
     *
     */
    @NotBlank(message = "AP编码不能为空")
    @Size(max = 50, message = "AP编码长度不能超过{max}位")
    private String apCode;
    /**
     * 附加参数
     */
    private JsonNode attach;

    public void freeData() {
        this.appId = null;
        this.openid = null;
        this.orderId = null;
        this.outTradeNo = null;
        this.thirdPartyOrder = null;
        this.body = null;
        this.personId = null;
        this.payAmount = null;
        this.ipAddress = null;
        this.notifyUrl = null;
        this.state = null;
        this.sendTime = null;
        this.apCode = null;
        this.updateTime = null;
        this.type = null;
        this.partner = null;
        this.subPartner = null;
        this.channelDetails = null;
        this.attach = null;
    }

//    public static void main(String[] args) {
//        String strt="attach=1542066281261490177&body=停车场预约停车缴费&channel_details={wx_lite=[{amount=0.01, sub_appid=wx6ff8cd570753a2af, sub_openid=o9_sO5iLs_8dkAlZKVm0xGarTh_U}]}&fee_type=1&input_charset=UTF-8¬ify_url=http://wx.tun.cdqidi.cn/sys/payOrder/tfPayNotify&out_trade_no=14885740630507841804236364766316&partner=1202851715&service=pay_service&service_version=1.1&spbill_create_ip=171.212.102.70&subject=预约停车&subpartner=1202851718&total_fee=0.01&trans_channel=wx_lite515bad0ba2f740ea8cea0c1a59fcbae0";
//        String sign = SecureUtil.md5(strt);
//        System.out.println(HashKit.md5(strt));
//    }
}
